Class {
	#name : 'SlotClassBuilderTest',
	#superclass : 'AbstractEnvironmentTestCase',
	#instVars : [
		'aClass',
		'anotherClass',
		'yetAnotherClass'
	],
	#category : 'Slot-Tests-ClassBuilder',
	#package : 'Slot-Tests',
	#tag : 'ClassBuilder'
}

{ #category : 'helpers-names' }
SlotClassBuilderTest >> aClassName [
	^ #SlotTestsClassA
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> anotherClassName [
	^ #SlotTestsClassB
]

{ #category : 'running' }
SlotClassBuilderTest >> assertTraitIntegrity [
	self assert: TOne traitUsers isHealthy.
	self assert: TOne classTrait traitUsers isHealthy.
	self assert: TTwo traitUsers isHealthy.
	self assert: TTwo classTrait traitUsers isHealthy
]

{ #category : 'running' }
SlotClassBuilderTest >> cleanUpTrait: trait [
	"During development some tests might invalidate the trait internal state.
	To avoid follow-up failures we reset the trait state here as good as possible."

	trait traitUsers removeAll.
	trait classTrait traitUsers removeAll
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> layoutClasses [
	^ { ByteLayout. WordLayout. FixedLayout. VariableLayout. WeakLayout }
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> layoutClassesWithSlots [
	^ { FixedLayout. VariableLayout. WeakLayout }
]

{ #category : 'helpers-building' }
SlotClassBuilderTest >> make: anUnaryBlock [
	"I build a class for testing, providing basic default values, but eventually customized by the received unary block."

	^ Smalltalk classInstaller make: [ :builder |
		  builder
			  superclass: Object;
			  name: self aClassName;
			  layoutClass: FixedLayout;
			  package: self slotTestPackageName.
		  anUnaryBlock value: builder ]
]

{ #category : 'helpers-building' }
SlotClassBuilderTest >> makeWithLayout: aClassLayout [
	^self makeWithLayout: aClassLayout andSlots: {}
]

{ #category : 'helpers-building' }
SlotClassBuilderTest >> makeWithLayout: aClassLayout andSlots: someSlots [
	"
	I create a class using the Slot class builder given a class layout and a collection of slots.
	"

	^self make: [:builder|
		builder
			layoutClass: aClassLayout;
			slots: someSlots
		]
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> slotTestPackageName [
	^ 'SlotTestsTmp'
]

{ #category : 'running' }
SlotClassBuilderTest >> tearDown [
	"We remove the classes that could have been created during test run"

	self class codeChangeAnnouncer suspendAllWhile: [
		{
			self aClassName.
			self anotherClassName.
			self yetAnotherClassName.
			self yetYetAnotherClassName } do: [ :each | testingEnvironment at: each ifPresent: [ :class | class removeFromSystem ] ] ].

	self class codeChangeAnnouncer unsubscribe: self.

	self
		cleanUpTrait: TOne;
		cleanUpTrait: TTwo.

	self packageOrganizer removePackage: self slotTestPackageName.

	super tearDown
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> yetAnotherClassName [
	^ #SlotTestsClassC
]

{ #category : 'helpers-names' }
SlotClassBuilderTest >> yetYetAnotherClassName [
	^ #SlotTestsClassD
]
